package com.runvp.common.hex;

import com.runvp.common.util.BigDecimalUtil;
import com.runvp.common.util.ToolUtils;

import java.math.BigDecimal;

/**
 * 重量换算工具
 *
 * @author xukk
 */
public class WeightCalcUtil {

    public static void main(String[] args) {
        System.out.println(decimal2Hex(100));
        System.out.println(hex2Decimal("64000000"));

        long data = 	74;
//        data = 333;
        System.out.println("重量: "+BigDecimalUtil.div(data,37));
        System.out.println("换算前:"+data);
        String dataHex = decimal2Hex(data);
        System.out.println("换算后:"+dataHex);
        System.out.println("还原后:"+hex2Decimal(dataHex));

    }

    /**
     * 16进制字符串(脉冲量) ，转10进制数字(脉冲数)
     *
     * @param weight
     * @return long
     */
    public static long hex2Decimal(String weight) {
        return BigDecimalUtil.vf(HexConvert.hexNumber2Ten(HexConvert.strTwoReversal(weight))).longValue();
    }


    /**
     * 10进制数字(脉冲数)转16进制字符串(脉冲量)
     *
     * @param weight
     * @return str
     */
    public static String decimal2Hex(long weight) {
        String all = HexConvert.numberTen2Hex(weight);
        //需要补零的个数
        int zeroNum = 8 - all.length();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < zeroNum; i++) {
            sb.append("0");
        }
        //补完0执行反转
        return HexConvert.strTwoReversal(sb.append(all).toString());
    }


}
